import Vue from 'vue'
import Router from 'vue-router'
import iView from 'iview'
import store from '../store'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: "/",
      name: "login",
      component: resolve => require(["../views/login/index.vue"], resolve)
    },
    {
      path: "/blacklist",
      name: "black search",
      component: resolve => require(["../components/common/L&R.vue"], resolve)
    },
    {
      path: "/blank",
      name: "blank",
      component: resolve => require(["../components/common/blank.vue"], resolve)
    },
    {
      path: "*",
      redirect: "/404"
    },
    {
      path: "/operatorReport",
      name: "operatorReport",
      component: resolve =>
        require(["../components/operatorReport.vue"], resolve)
    },
    {
      path: "/401",
      name: "401",
      component: resolve => require(["../views/error/401.vue"], resolve)
    },
    {
      path: "/404",
      name: "404",
      component: resolve => require(["../views/error/404.vue"], resolve)
    },
    {
      path: "/home",
      name: "home",
      component: resolve => require(["../components/main/main.vue"], resolve),
      children: [
        {
          path: "/home",
          name: "home",
          component: resolve => require(["../views/home/home.vue"], resolve)
        },
        {
          //用户列表
          path: "/paymentBills",
          name: "paymentBills",
          component: resolve =>
            require(["../components/paymentBills.vue"], resolve)
        },
        {
          //认证管理
          path: "/identify",
          name: "identify",
          component: resolve => require(["../components/identify.vue"], resolve)
        },
        {
          //初审管理
          path: "/chuShen",
          name: "chuShen",
          component: resolve => require(["../components/chuShen.vue"], resolve)
        },
        //  初审分配
        {
          path: "/approvalManageFirstAllocation",
          name: "approvalManageFirstAllocation",
          component: resolve =>
            require([
              "../views/ApprovalManage/FirstAllocation/index.vue"
            ], resolve)
        },
        //  初审审核
        {
          path: "/approvalManageFirstReview",
          name: "approvalManageFirstReview",
          component: resolve =>
            require(["../views/ApprovalManage/FirstReview/index.vue"], resolve)
        },
        //  终审分配
        {
          path: "/approvalManageLastAllocation",
          name: "approvalManageLastAllocation",
          component: resolve =>
            require([
              "../views/ApprovalManage/LastAllocation/index.vue"
            ], resolve)
        },
        //  终审审核
        {
          path: "/approvalManageLastReview",
          name: "approvalManageLastReview",
          component: resolve =>
            require(["../views/ApprovalManage/LastReview/index.vue"], resolve)
        },
        {
          //终审管理
          path: "/zhongShen",
          name: "zhongShen",
          component: resolve =>
            require(["../components/zhongShen.vue"], resolve)
        },
        {
          //审批统计
          path: "/shenTong",
          name: "shenTong",
          component: resolve => require(["../components/shenTong.vue"], resolve)
        },
        {
          //催收管理- 我的工作台
          path: "/collectionMyWorkbench",
          name: "collectionMyWorkbench",
          component: resolve =>
            require(["../components/collectionMyWorkbench.vue"], resolve)
        },
        {
          //审批管理- 我的工作台
          path: "/approvalMyWorkbench",
          name: "approvalMyWorkbench",
          component: resolve =>
            require(["../components/approvalMyWorkbench.vue"], resolve)
        },
        {
          path: "/fkFail",
          name: "fkFail",
          component: resolve => require(["../views/fkManage/fail.vue"], resolve)
        },
        {
          //订单列表
          path: "/orderManager",
          name: "orderManager",
          component: resolve => require(["../views/order/list.vue"], resolve)
        },
        {
          //财务对账
          path: "/finance",
          name: "finance",
          component: resolve =>
            require(["../components/financeManager.vue"], resolve)
        },
        {
          //平账管理
          path: "/average",
          name: "average",
          component: resolve =>
            require(["../views/finance/average.vue"], resolve)
        },
        {
          //收支统计
          path: "/andPaymentsStatistics",
          name: "andPaymentsStatistics",
          component: resolve =>
            require(["../views/finance/andPaymentsStatistics.vue"], resolve)
        },
        {
          // 回款记录 回款流水
          path: "/returnMoney",
          name: "returnMoney",
          component: resolve =>
            require(["../views/finance/returnMoney.vue"], resolve)
        },

        // {//支付账户
        // 	path: '/payAccount',
        // 	name: 'payAccount',
        // 	component: resolve => require(['../views/finance/payAccount.vue'], resolve)
        // },
        {
          // s0账单
          path: "/billS0",
          name: "billS0",
          component: resolve => require(["../components/billS0.vue"], resolve)
        },
        {
          //账单催收
          path: "/billS1",
          name: "billS1",
          component: resolve => require(["../components/billS1.vue"], resolve)
        },
        {
          //账单催收4-10
          path: "/billS2",
          name: "billS2",
          component: resolve => require(["../components/billS2.vue"], resolve)
        },
        {
          //账单催收11-15
          path: "/billM2",
          name: "billM2",
          component: resolve => require(["../components/billM2.vue"], resolve)
        },
        {
          //账单催收16-30
          path: "/billM3",
          name: "billM3",
          component: resolve => require(["../components/billM3.vue"], resolve)
        },
        {
          //账单催收31-60
          path: "/m2Order",
          name: "m2Order",
          component: resolve => require(["../components/m2Order.vue"], resolve)
        },
        {
          //异常账单
          path: "/abnormalOrder",
          name: "abnormalOrder",
          component: resolve =>
            require(["../components/abnormalOrder.vue"], resolve)
        },
        {
          //催收异常账单
          path: "/abnormalOutsource",
          name: "abnormalOutsource",
          component: resolve =>
            require(["../components/abnormalOutsource.vue"], resolve)
        },
        {
          //坏账账单
          path: "/billBad",
          name: "billBad",
          component: resolve => require(["../components/billBad.vue"], resolve)
        },
        {
          //催收总账单
          path: "/billCollection",
          name: "billCollection",
          component: resolve =>
            require(["../components/billCollection.vue"], resolve)
        },

        {
          //催收标签
          path: "/billLabel",
          name: "billLabel",
          component: resolve =>
            require(["../components/billLabel.vue"], resolve)
        },
        {
          //催收统计
          path: "/billStatistics",
          name: "billStatistics",
          component: resolve =>
            require(["../views/billStatistics/index.vue"], resolve)
        },
        // {
        //   //催收统计副
        //   path: "/billStatisticsS",
        //   name: "billStatisticsS",
        //   component: resolve =>
        //     require(["../components/billStatistics.vue"], resolve)
        // },

        {
          //用户数据报表
          path: "/userData",
          name: "userData",
          component: resolve =>
            require(["../views/report/userData.vue"], resolve)
        },
        {
          //贷款数据报表
          path: "/loanData",
          name: "loanData",
          component: resolve =>
            require(["../views/report/loanData.vue"], resolve)
        },
        {
          //贷款数据报表
          path: "/loanDataS",
          name: "loanDataS",
          component: resolve =>
            require(["../views/report/loanData.vue"], resolve)
        },
        {
          //逾期数据报表
          path: "/overdueData",
          name: "overdueData",
          component: resolve =>
            require(["../views/report/overdueData.vue"], resolve)
        },
        {
          //导流平台管理
          path: "/platformManage",
          name: "platformManage",
          component: resolve => require(["../views/platform/list.vue"], resolve)
        },
        {
          //导流平台详情
          path: "/platManageInfo",
          name: "platManageInfo",
          component: resolve =>
            require(["../components/platManageInfo.vue"], resolve)
        },
        {
          //导流平台详情
          path: "/platformTool",
          name: "platformTool",
          component: resolve =>
            require(["../components/platformTool.vue"], resolve)
        },
        {
          //用户反馈
          path: "/feedback",
          name: "feedback",
          component: resolve => require(["../components/feedback.vue"], resolve)
        },
        {
          //消息通知
          path: "/messageNotice",
          name: "messageNotice",
          component: resolve =>
            require(["../components/messageNotice.vue"], resolve)
        },
        {
          //管理员设置
          path: "/administrator",
          name: "administrator",
          component: resolve =>
            require(["../components/administrator.vue"], resolve)
        },
        {
          //版本记录
          path: "/version",
          name: "version",
          component: resolve => require(["../components/version.vue"], resolve)
        },
        {
          //模型配置
          path: "/modelConfig",
          name: "modelConfig",
          component: resolve =>
            require(["../views/risk/modelConfig.vue"], resolve)
        },
        {
          //模型统计
          path: "/modelStatistics",
          name: "modelStatistics",
          component: resolve =>
            require(["../views/risk/modelStatistics.vue"], resolve)
        },
        {
          //拦截统计
          path: "/riskIntercept",
          name: "riskIntercept",
          component: resolve =>
            require(["../components/riskIntercept.vue"], resolve)
        },
        {
          //dpd统计
          path: "/dpdCount",
          name: "dpdCount",
          component: resolve => require(["../components/dpdCount.vue"], resolve)
        },
        {
          //渠道画像
          path: "/channelPortrait",
          name: "channelPortrait",
          component: resolve =>
            require(["../views/risk/channelPortrait.vue"], resolve)
        },
        {
          //版本记录
          path: "/operationLog",
          name: "operationLog",
          component: resolve =>
            require(["../views/report/operationLog.vue"], resolve)
        },
        {
          // banner管理
          path: "/banner",
          name: "banner",
          component: resolve => require(["../views/banner/banner.vue"], resolve)
        },
        {
          // 直投客户
          path: "/investor",
          name: "investor",
          component: resolve => require(["../views/investor/list.vue"], resolve)
        },
        {
          // 产品配置
          path: "/systemConfig",
          name: "systemConfig",
          component: resolve =>
            require(["../views/system/systemConfig.vue"], resolve)
        },
        {
          // 产品配置
          path: "/productConfig",
          name: "productConfig",
          component: resolve =>
            require(["../views/system/productConfig.vue"], resolve)
        },
        {
          // 催收标签配置
          path: "/collectionConfig",
          name: "collectionConfig",
          component: resolve =>
            require(["../views/system/collectionConfig.vue"], resolve)
        },
        {
          // 用户转化
          path: "/userConversion",
          name: "userConversion",
          component: resolve =>
            require(["../views/user/userConversion.vue"], resolve)
        },
        {
          // 测试白名单
          path: "/whitelist",
          name: "whitelist",
          component: resolve =>
            require(["../views/system/whitelist.vue"], resolve)
        },
        {
          // 贷款超市列表页
          path: "/marketList",
          name: "marketList",
          component: resolve => require(["../views/market/list.vue"], resolve)
        },
        {
          // 贷款超市统计
          path: "/marketStatistics",
          name: "marketStatistics",
          component: resolve =>
            require(["../views/market/statistics.vue"], resolve)
        },
        {
          // 支付渠道配置
          path: "/payConfig",
          name: "payConfig",
          component: resolve =>
            require(["../views/system/payConfig.vue"], resolve)
        },
        {
          // 批量代扣
          path: "/batchWithhold",
          name: "batchWithhold",
          component: resolve =>
            require(["../views/order/batch-withhold.vue"], resolve)
        },
        {
          // 公告管理
          path: "/notice",
          name: "notice",
          component: resolve => require(["../views/notice/list.vue"], resolve)
        },
        {
          // 运营管理-老客户激活
          path: "/customerActivation",
          name: "customerActivation",
          component: resolve =>
            require(["../views/customer/activation/index.vue"], resolve)
        },
        {
          // 运营管理-老客户分配
          path: "/customerAllocation",
          name: "customerAllocation",
          component: resolve =>
            require(["../views/customer/customerAllocation.vue"], resolve)
        },
        {
          // 运营管理-老客户分配
          path: "/blacklistBank",
          name: "blacklistBank",
          component: resolve =>
            require(["../views/blacklistBank/index.vue"], resolve)
        }
        // {
        //   // 提额配置
        //   path: "/withdraw",
        //   name: "withdraw",
        //   component: resolve => require(["../views/withdraw/withdraw.vue"], resolve)
        // }
      ]
    }
  ]
});

const LOGIN_NAME = 'login';

//7.11使用新的接口获取用户角色配置（test1）
// router.beforeEach((to, from, next) => {
// 	iView.LoadingBar.start();
// 	if (to.name === LOGIN_NAME) {
// 		next();
// 	} else {
// 		Vue.http.post('/sys/account/login')
// 		.then((response) => {
// 			if (response.body.code === 0) {
// 				store.dispatch('setType', data.type);
// 				store.dispatch('setLevel', data.level);
// 				store.dispatch('setLoginName', data.managerName);
// 				next();
// 			} else {
// 				next('/');
// 			}
// 		}, error => {
// 			next('/');
// 		});
// 	}
// });

//7.10 用户角色配置（localstorage）
router.beforeEach((to, from, next) => {
  iView.LoadingBar.start();
  if (to.name === LOGIN_NAME) {
    next();
  } else {
    if (sessionStorage.peacock) {
      next();
    } else {
      iView.LoadingBar.finish();
      next('/');
      // 修改登录速度慢

    }
  }
});

router.afterEach(to => {
  iView.LoadingBar.finish();
  window.scrollTo(0, 0);
});

export default router;
